<template>

  <el-select
    v-model="bedId"
    placeholder="请选择关联房间"
    filterable
    clearable
    :disabled="disabled"
  >
    <el-option
      v-for="dict in roomList"
      :key="dict.id"
      :label="dict.bedName"
      :value="dict.id"
    />
  </el-select>


</template>

<script>


import {byRoomList} from "@/api/collegebase/accommodationReside";

export default {
  name: "CollegeBedSelector",
  props: {
    value: {
      type: String,
      default: ''
    },
    disabled: {
      type: Boolean,
      default: false
    },
    roomId: {
      type: String,
      default: ''
    },
  }
  ,
  model: {
    prop: 'value',
    event: 'change'
  },
  data() {
    return {
      roomList: [],
      bedId: '',
    };
  },

  created() {
  },

  watch: {
    bedId(value) {
      this.$emit('change', value)
    },
    roomId: {
      immediate: true,
      handler(newVal, oldVal) {
        if (oldVal) {
          this.bedId = '';
        } else {
          this.bedId = this.value;
        }
        this.getBedListData(newVal);
      }
    },
    value(value) {
      // console.info("专业 执行value 操作：", value)
      this.bedId = value;
    }
  },
  methods: {
    //获取
    async getBedListData(roomId) {
      if (null == roomId || '' == roomId) {
        this.roomList = []
        return;
      }
      const rootRespList =await byRoomList(roomId);
      this.roomList = rootRespList.data;
    },

    clear() {
      this.$emit("change", '')
    }


  }

}
</script>

